var windowName = "siteInfo";
var Page
apiready = function(){
    onWindowShow(function () {
        var cur = getLocData("curSite")
        Page.curSite = cur;
        getData(Page)
    })
    onWindowHide(function () {
    })
    Page = createVM("#Page",{
        //页面数据
        curSite:{},
        list:[],
        matters:[],
        en:{id:"",sid:"",mid:"",tips:"",num:""},
        tab:0,
        open:false,
        index:0,
        got:0,
    },{
        //页面方法
        init:function () {
        }
        ,OnPullDownRefresh:function () {
            startPullDownRefresh()
            getData(this)
        }
        ,submit:function() {
            var _this = this
            this.en.sid = this.curSite.id
            this.$refs.form.validate().then((result) => {
                logJson(result)
                if (result){
                    var form = createForm(this.en);
                    form["sid"] = this.en.sid
                    apiPost("/app/site/matter",form,function (res) {
                        // log(res)
                        _this.en = clearEn(_this.en)
                        getData(_this)
                        showToast(res.message)
                    })

                }else{
                    showToast("请检查输入")
                }
            });
        },
        select: function (index) {
            this.open = true
            this.index = index
        },
        del: function (index) {
            var _this = this
            var item = this.list[index]
            this.open = false
            apiGet("/app/site/matter/del",{id:item.id},function (res) {
                if (res.s == 1) {
                    getData(_this)
                    _this.list = arrayDelIndex(_this.list,index)
                }

            })
        },
        edit: function (index) {
            var _this = this
            var item = this.list[index]
            if (item.tips == null) {
                item.tips = ''
            }
            _this.en = item
            _this.tab = 1
            this.open = false
        },
        cancel: function () {
            this.open = false
        },
        getIt: function (index) {
            var item = this.list[index]

            goto("siteMatterLog",{item:item})

        }
    })

    Page.init()

}

function getData(_this) {
    var sid = _this.curSite.id
    startPullDownRefresh()
    apiGet("/app/site/matter",{sid:sid},function (res) {
        stopPullDownRefresh()
        _this.list = res.data.list
        _this.matters = res.data.matters
        if (!isFalse(res.data.list)) {
            _this.tab = 1
        }else {
            _this.tab = 0
        }
    })
}